package com.econ.powercloud.ems.common.enums;

import java.text.SimpleDateFormat;

/**
 * @author zjr
 * @desciption 时间间隔枚举类
 */
public enum TimeIntervalType implements EnumMethod {

    SECOND(5,"秒级",1000L,new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")),
    ONE_MINS(0,"1分钟",60000L,new SimpleDateFormat("yyyy-MM-dd HH:mm")),
    FIVE_MINS(1,"5分钟",300000L,new SimpleDateFormat("yyyy-MM-dd HH:mm")),
    FIFTEEN_MINS(2,"15分钟",900000L,new SimpleDateFormat("yyyy-MM-dd HH:mm")),
    THIRTY_MINS(3,"30分钟",1800000L,new SimpleDateFormat("yyyy-MM-dd HH:mm")),
    ONE_HOUR(4, "1小时",3600000L,new SimpleDateFormat("yyyy-MM-dd HH")),
    ;

    private Integer code;
    private String desc;
    //毫秒数
    private Long milliseconds;
    //对应的日期转化格式
    private SimpleDateFormat sdf;

    @Override
    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Long getMilliseconds() {
        return milliseconds;
    }

    public void setMilliseconds(Long milliseconds) {
        this.milliseconds = milliseconds;
    }

    public SimpleDateFormat getSdf() {
        return sdf;
    }

    TimeIntervalType(Integer code, String desc, Long milliseconds, SimpleDateFormat sdf) {
        this.code = code;
        this.desc = desc;
        this.milliseconds = milliseconds;
        this.sdf = sdf;
    }

    /**
     * 根据时间Index获取时间间隔
     * @param code
     * @return
     */
    public static TimeIntervalType fromCode(Integer code){
        for(TimeIntervalType intervalType: TimeIntervalType.values()){
            if(intervalType.getCode().equals(code)){
                return intervalType;
            }
        }
        return FIFTEEN_MINS;
    }
}
